package com.rope.backEnd.controller;
import com.rope.backEnd.pojo.ChatHistory;
import com.rope.backEnd.pojo.Result;
import com.rope.backEnd.service.ChatHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Slf4j
@RestController
public class ChatHistoryController {
    @Autowired
    private ChatHistoryService chatHistoryService;

    //查询所有的图片数据
    @GetMapping("/chatHistorySUL")
    public Result list(){
        log.info("查询数据");
        List<ChatHistory> chatHistory = chatHistoryService.list();
        return Result.success(chatHistory);

    }

//    将聊天记录放入数据库
    @PostMapping("/chatHistoryCommentInformation")
    public ResponseEntity<String> commentInformation(@RequestBody ChatHistory chatHistory){
        int input = chatHistoryService.input(chatHistory);
        if(input != 0){
            return ResponseEntity.ok("评论成功");//评论成功;
        }
        else {
            return ResponseEntity.ok("评论失败");//评论失败;
        }
    }

}
